package com.jxd.esuntils;

import com.jxd.entity.MesContent;
import com.jxd.entity.MesHead;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class AddElasticsearch {
    //写入41040 控制报文
    public List<MesContent> GetComMess(List<MesHead> mesHeads){
        List<MesContent> comMesList = new ArrayList<>();
        String mesComs [] = {
                "'B0BF'","D0FF","D000"
        };
        for (int i = 0; i < mesHeads.size(); i++) {
            for (int j = 2; j <7 ; j++) {
                MesContent mesContent = new MesContent();
                String rowKey = mesHeads.get(i).getMesSignId()+"-"+j;
                String mesSignId = mesHeads.get(i).getMesSignId();
                if(j==6){
                    int n = (int) (Math.random() * 3);
                    mesContent.setRowkey(rowKey);
                    mesContent.setMesSignId(mesSignId);
                    mesContent.setId(String.valueOf(j));
                    mesContent.setCode(mesComs[n]);
                    comMesList.add(mesContent);
                }else {
                    mesContent.setRowkey(rowKey);
                    mesContent.setMesSignId(mesSignId);
                    mesContent.setId(String.valueOf(j));
                    mesContent.setCode("1111");
                    comMesList.add(mesContent);
                }
            }

        }
        return comMesList;
    }

    //写入 41008 工作模式选择报文
    public List<MesContent> GetWorkMess(List<MesHead> mesHeads){
        List<MesContent> comMesList = new ArrayList<>();
        String[] mesCams = {
                "'0001'","'0000'","'0002'","'0004'"
        };

        for (int i = 0; i < mesHeads.size(); i++) {
                MesContent mesContent = new MesContent();
                String rowKey = mesHeads.get(i).getMesSignId() + "-2";
                String mesSignId = mesHeads.get(i).getMesSignId();
                int n = (int) (Math.random() * 4);
                mesContent.setRowkey(rowKey);
                mesContent.setMesSignId(mesSignId);
                mesContent.setId(String.valueOf(2));
                mesContent.setCode(mesCams[n]);
                comMesList.add(mesContent);
        }

        return comMesList;
    }
    //写入 61616 配置更新报文报文
    public List<MesContent> GetupdateMess(List<MesHead> mesHeads){
        List<MesContent> comMesList = new ArrayList<>();
        String[] types ={"ABC10_M","ABC10","ABV18"};
        for (int i = 0; i < mesHeads.size(); i++) {
            for (int j = 1; j <=8; j++) {
                MesContent mesContent = new MesContent();
                int a =(int) (Math.random() * 3);
                int n = (j*18)+1;
                System.out.println(n);
                String rowKey = mesHeads.get(i).getMesSignId() + "-" + n;
                String mesSignId = mesHeads.get(i).getMesSignId();
                mesContent.setRowkey(rowKey);
                mesContent.setMesSignId(mesSignId);
                mesContent.setId(String.valueOf(n));
                mesContent.setCode(types[a]);
                comMesList.add(mesContent);
            }
        }
        return  comMesList;
    }

    //写入 61456 心跳报文
    public List<MesContent> GetHeartbeatMess(List<MesHead> mesHeads){
        List<MesContent> comMesList = new ArrayList<>();
        for (int i = 0; i < mesHeads.size(); i++) {
            for (int j = 10; j <=12; j++) {
                MesContent mesContent = new MesContent();
                String rowKey = mesHeads.get(i).getMesSignId() + "-" + j;
                String mesSignId = mesHeads.get(i).getMesSignId();
                int n = (int) (Math.random() * 2);
                mesContent.setRowkey(rowKey);
                mesContent.setMesSignId(mesSignId);
                mesContent.setId(String.valueOf(j));
                System.out.println(n);
                mesContent.setCode(String.valueOf(n));
                comMesList.add(mesContent);
            }
        }
        return  comMesList;
    }
    //写入故障61632报文报文
    public List<MesContent> GetFaultMessF(List<MesHead> mesHeads){
        List<MesContent> comMesList = new ArrayList<>();
        String[]faults = {
                "'0310'","'031F'","0320","032F"
        };
        for (int i = 0; i < mesHeads.size(); i++) {
            int n = (int) (Math.random() * 3);
            System.out.println("n===="+n);
            for (int j = 2; j <=3+n; j++) {
                if (j==2){
                    MesContent mesContent = new MesContent();
                    String rowKey = mesHeads.get(i).getMesSignId() + "-" + j;
                    String mesSignId = mesHeads.get(i).getMesSignId();
                    mesContent.setRowkey(rowKey);
                    mesContent.setMesSignId(mesSignId);
                    mesContent.setId(String.valueOf(j));
                    mesContent.setCode(faults[n]);
                    comMesList.add(mesContent);
                }else if (j==3){
                        MesContent mesContent = new MesContent();
                        String rowKey = mesHeads.get(i).getMesSignId() + "-" + j;
                        String mesSignId = mesHeads.get(i).getMesSignId();
                        mesContent.setRowkey(rowKey);
                        mesContent.setMesSignId(mesSignId);
                        mesContent.setId(String.valueOf(j));
                            String code = "000"+n;
                            System.out.println("code=="+code);
                            mesContent.setCode(code);
                        comMesList.add(mesContent);
                }else {
                    System.out.println("j======="+j);
                    MesContent mesContent = new MesContent();
                    String rowKey = mesHeads.get(i).getMesSignId() + "-" + j;
                    String mesSignId = mesHeads.get(i).getMesSignId();
                    mesContent.setRowkey(rowKey);
                    mesContent.setMesSignId(mesSignId);
                    mesContent.setId(String.valueOf(j));
                    mesContent.setCode(UUID.randomUUID().toString().replace("-", ""));
                    comMesList.add(mesContent);
                }

            }
        }

        return  comMesList;
    }

    public List<MesContent> GetFaultMess(List<MesHead> mesHeads){
        List<MesContent> comMesList = new ArrayList<>();
        String[]faults = {
                "代码1'","'代码2'","代码3","代码4"
        };
        for (int i = 0; i < mesHeads.size(); i++) {
            int n = (int) (Math.random() * 3);
            for (int j = 2; j <=3+n; j++) {
                if (j==2){
                    MesContent mesContent = new MesContent();
                    String rowKey = mesHeads.get(i).getMesSignId() + "-" + j;
                    String mesSignId = mesHeads.get(i).getMesSignId();
                    mesContent.setRowkey(rowKey);
                    mesContent.setMesSignId(mesSignId);
                    mesContent.setId(String.valueOf(j));
                    mesContent.setCode(faults[n]);
                    comMesList.add(mesContent);
                }else if (j==3){
                    MesContent mesContent = new MesContent();
                    String rowKey = mesHeads.get(i).getMesSignId() + "-" + j;
                    String mesSignId = mesHeads.get(i).getMesSignId();
                    mesContent.setRowkey(rowKey);
                    mesContent.setMesSignId(mesSignId);
                    mesContent.setId(String.valueOf(j));
                    String code = "000"+n;
                    mesContent.setCode(code);
                    comMesList.add(mesContent);
                }else {
                    MesContent mesContent = new MesContent();
                    String rowKey = mesHeads.get(i).getMesSignId() + "-" + j;
                    String mesSignId = mesHeads.get(i).getMesSignId();
                    mesContent.setRowkey(rowKey);
                    mesContent.setMesSignId(mesSignId);
                    mesContent.setId(String.valueOf(j));
                    mesContent.setCode(UUID.randomUUID().toString().replace("-", ""));
                    comMesList.add(mesContent);
                }

            }
        }

        return  comMesList;
    }
//53286
    public List<MesContent> GetFaultMessD(List<MesHead> mesHeads){
        List<MesContent> comMesList = new ArrayList<>();
        String[]faults = {
                "'0310'","'031F'","0320","032F"
        };
        for (int i = 0; i < mesHeads.size(); i++) {
            int n = (int) (Math.random() * 3);
            System.out.println("n===="+n);
            for (int j = 2; j <=3+n; j++) {
                if (j==2){
                    MesContent mesContent = new MesContent();
                    String rowKey = mesHeads.get(i).getMesSignId() + "-" + j;
                    String mesSignId = mesHeads.get(i).getMesSignId();
                    mesContent.setRowkey(rowKey);
                    mesContent.setMesSignId(mesSignId);
                    mesContent.setId(String.valueOf(j));
                    mesContent.setCode(faults[n]);
                    comMesList.add(mesContent);
                }else if (j==3){
                    MesContent mesContent = new MesContent();
                    String rowKey = mesHeads.get(i).getMesSignId() + "-" + j;
                    String mesSignId = mesHeads.get(i).getMesSignId();
                    mesContent.setRowkey(rowKey);
                    mesContent.setMesSignId(mesSignId);
                    mesContent.setId(String.valueOf(j));
                    String code = "000"+n;
                    System.out.println("code=="+code);
                    mesContent.setCode(code);
                    comMesList.add(mesContent);
                }else {
                    System.out.println("j======="+j);
                    MesContent mesContent = new MesContent();
                    String rowKey = mesHeads.get(i).getMesSignId() + "-" + j;
                    String mesSignId = mesHeads.get(i).getMesSignId();
                    mesContent.setRowkey(rowKey);
                    mesContent.setMesSignId(mesSignId);
                    mesContent.setId(String.valueOf(j));
                    mesContent.setCode(UUID.randomUUID().toString().replace("-", ""));
                    comMesList.add(mesContent);
                }

            }
        }

        return  comMesList;
    }

    public List<MesContent> GetFaultMessC(List<MesHead> mesHeads){
        List<MesContent> comMesList = new ArrayList<>();
        String[]faults = {
                "'0310'","'031F'","0320","032F"
        };
        for (int i = 0; i < mesHeads.size(); i++) {
            int n = (int) (Math.random() * 3);
            System.out.println("n===="+n);
            for (int j = 2; j <=3+n; j++) {
                if (j==2){
                    MesContent mesContent = new MesContent();
                    String rowKey = mesHeads.get(i).getMesSignId() + "-" + j;
                    String mesSignId = mesHeads.get(i).getMesSignId();
                    mesContent.setRowkey(rowKey);
                    mesContent.setMesSignId(mesSignId);
                    mesContent.setId(String.valueOf(j));
                    mesContent.setCode(faults[n]);
                    comMesList.add(mesContent);
                }else if (j==3){
                    MesContent mesContent = new MesContent();
                    String rowKey = mesHeads.get(i).getMesSignId() + "-" + j;
                    String mesSignId = mesHeads.get(i).getMesSignId();
                    mesContent.setRowkey(rowKey);
                    mesContent.setMesSignId(mesSignId);
                    mesContent.setId(String.valueOf(j));
                    String code = "000"+n;
                    System.out.println("code=="+code);
                    mesContent.setCode(code);
                    comMesList.add(mesContent);
                }else {
                    System.out.println("j======="+j);
                    MesContent mesContent = new MesContent();
                    String rowKey = mesHeads.get(i).getMesSignId() + "-" + j;
                    String mesSignId = mesHeads.get(i).getMesSignId();
                    mesContent.setRowkey(rowKey);
                    mesContent.setMesSignId(mesSignId);
                    mesContent.setId(String.valueOf(j));
                    mesContent.setCode(UUID.randomUUID().toString().replace("-", ""));
                    comMesList.add(mesContent);
                }

            }
        }

        return  comMesList;
    }

}
